using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;
using System.Data.SqlClient;

namespace Acms.SqlDal
{
    public class SearchDal : PostDal
    {
        public new enum Fields
        {
            Rank
        }

        protected override void ReadRecord(System.Collections.Hashtable table, System.Data.SqlClient.SqlDataReader reader)
        {
            base.ReadRecord(table, reader);
            GetReaderValue<int>(Fields.Rank, reader, table);
        }

        public Hashtable[] GetAllByTopicAndSearchTerm(int topicId, string searchTerm, int startIndex, int maxRecords, ref int totalRecords)
        {
            SqlCommand cmd = CreateCommand("GetAllByTopicAndSearchTerm");
            AddInputParameter(cmd, "TopicId", topicId, System.Data.SqlDbType.Int);
            AddInputParameter(cmd, "SearchTerm", searchTerm, System.Data.SqlDbType.VarChar, 50);
            AddInputParameter(cmd, "StartIndex", startIndex, System.Data.SqlDbType.Int);
            AddInputParameter(cmd, "MaxRecords", maxRecords, System.Data.SqlDbType.Int);
            AddOutputParameter(cmd, "TotalRecordsOut", System.Data.SqlDbType.Int);

            Hashtable[] tables = ExecuteGetCollection(cmd);

            totalRecords = GetOutputValue<int>(cmd, "TotalRecordsOut");

            return tables;
        }
    }
}
